package com.daz.manager.guideTheme.action;

import java.util.Date;
import java.util.HashMap;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import com.daz.manager.guideTheme.pojo.GuideTheme;
import com.daz.manager.guideTheme.server.IGuideThemeSV;
import com.daz.manager.loginHis.pojo.LoginHis;
import com.github.pagehelper.PageInfo;
import com.opensymphony.xwork2.ActionSupport;

public class GuideThemeAction extends ActionSupport{

	@Autowired
	private IGuideThemeSV sv;
	
	private String themeId;
    private String themeName;
    private Date createDate;
    private String remark;
    private String contentText;
    private String status;
    
    private PageInfo<GuideTheme> resultsList;
	private List<GuideTheme> list;
	private GuideTheme pojo;
	private String msg;
    private Boolean success;
    private String limit;
    private String page;
    private String query;
    
    public String getWorkTheme(){
    	HashMap map = new HashMap<String, Object>();
    	map.put("status", 1);
    	try {
			resultsList = sv.qryByPrimaryKey( map,0, 0);
			pojo = resultsList.getList().get(0);
			if(pojo != null){
				themeName = pojo.getThemeName();
			}
			
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    	return SUCCESS;
    }
    public String querylist(){
    	HashMap map = new HashMap<String, Object>();
    	
        if(themeId != null){
        	map.put("themeId", themeId);
        }
        if(themeName != null){
        	map.put("themeName", themeName);
        }
        if(createDate != null){
        	map.put("createDate", createDate);
        }
        if(status != null){
        	map.put("status", status);
        }   
        if(contentText != null){
        	map.put("contentText", contentText);
        }
        if(query != null){
        	map.put("query", query);
        }
    	int p= 0;
    	int s=0;
    	if(page != null){
    		p = Integer.parseInt(page);
    	}
    	if(limit != null){
    		s = Integer.parseInt(limit);
    	}
    	Integer.parseInt(page);
    	try {
    		resultsList = sv.qryByPrimaryKey( map, p, s);
			this.setSuccess(true);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			this.setSuccess(false);
			this.setMsg(e.getMessage());
		}
    	return SUCCESS;
    }
    
    public String insert(){
    	GuideTheme value = new GuideTheme();
    	value.setContentText(contentText);
    	value.setCreateDate(new Date());
    	value.setRemark(remark);
    	value.setStatus(status);
    	value.setThemeName(themeName);
    	if("1".equals(status)){
			this.updateNotWork();
		}
    	try {
			sv.insertSelective(value);
			this.setSuccess(true);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			this.setSuccess(false);
			this.setMsg(e.getMessage());
		}
    	return SUCCESS;
    }
    
    public String delete(){
    	try {
			sv.deleteByPrimaryKey(themeId);
			this.setSuccess(true);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			this.setSuccess(false);
			this.setMsg(e.getMessage());
		}
    	return SUCCESS;
    }
    
    
    public String update(){
    	GuideTheme value = new GuideTheme();
    	value.setThemeId(themeId);
    	value.setContentText(contentText);
    	value.setCreateDate(createDate);
    	value.setRemark(remark);
    	value.setStatus(status);
    	value.setThemeName(themeName);
    	if("1".equals(status)){
			this.updateNotWork();
		}
    	try {
			sv.updateByPrimaryKeySelective(value);
			this.setSuccess(true);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			this.setSuccess(false);
			this.setMsg(e.getMessage());
		}
    	return SUCCESS;
    }
    
    private void updateNotWork(){
    	HashMap map = new HashMap<String, Object>();
    	map.put("status", "1");
    	try {
			resultsList = sv.qryByPrimaryKey( map, 0, 0);
			list = resultsList.getList();
			for(int i=0;i<list.size();i++){
				GuideTheme value = new GuideTheme();
				value = list.get(i);
				value.setStatus("0");
				sv.updateByPrimaryKeySelective(value);
				
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    }
    
	public String getThemeId() {
		return themeId;
	}

	public void setThemeId(String themeId) {
		this.themeId = themeId;
	}

	public String getThemeName() {
		return themeName;
	}

	public void setThemeName(String themeName) {
		this.themeName = themeName;
	}

	public Date getCreateDate() {
		return createDate;
	}

	public void setCreateDate(Date createDate) {
		this.createDate = createDate;
	}

	

	public String getContentText() {
		return contentText;
	}

	public void setContentText(String contentText) {
		this.contentText = contentText;
	}

	public String getStatus() {
		return status;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	public PageInfo<GuideTheme> getResultsList() {
		return resultsList;
	}

	public void setResultsList(PageInfo<GuideTheme> resultsList) {
		this.resultsList = resultsList;
	}

	public List<GuideTheme> getList() {
		return list;
	}

	public void setList(List<GuideTheme> list) {
		this.list = list;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	public Boolean getSuccess() {
		return success;
	}

	public void setSuccess(Boolean success) {
		this.success = success;
	}

	public String getLimit() {
		return limit;
	}

	public void setLimit(String limit) {
		this.limit = limit;
	}

	public String getPage() {
		return page;
	}

	public void setPage(String page) {
		this.page = page;
	}

	public String getQuery() {
		return query;
	}

	public void setQuery(String query) {
		this.query = query;
	}

	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}
	public GuideTheme getPojo() {
		return pojo;
	}
	public void setPojo(GuideTheme pojo) {
		this.pojo = pojo;
	}
    
    
}
